//
//  ZCAddressListCell.m
//  ZCJZ
//
//  Created by sujeking on 2019/2/28.
//  Copyright © 2019年 jeking. All rights reserved.
//

#import "ZCAddressListCell.h"
#import "TBCityIconFont.h"
#import "generalToolBox.h"
@interface ZCAddressListCell()

@property (weak, nonatomic) IBOutlet UIButton *defaultBtn;
@property (weak, nonatomic) IBOutlet UILabel *nameAndphoneLabel;
@property (weak, nonatomic) IBOutlet UIImageView *checkImv;
@property (weak, nonatomic) IBOutlet UIButton *editBtn;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leftc;

@end


@implementation ZCAddressListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    [self setupSubViews];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    if (selected) {
        self.checkImv.image = [UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e648", 25, [generalToolBox getColorWithHexadecimalColorStr:@"0xC20114"])];
    } else {
        self.checkImv.image = [UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e647", 25,  [generalToolBox getColorWithHexadecimalColorStr:@"0xC20114"])];
    }
}

- (void)setupSubViews {
    self.defaultBtn.hidden = YES;
    UIImage *img = [UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e63c", 30, [generalToolBox getColorWithHexadecimalColorStr:@"0x666666"])];
    img = [img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [self.editBtn setTitle:nil forState:UIControlStateNormal];
    [self.editBtn setImage:img forState:UIControlStateNormal];
    
    [self.editBtn addTarget:self action:@selector(editButtonClickAction)
           forControlEvents:UIControlEventTouchUpInside];
}

- (void)setDict:(NSDictionary *)dict {
    _dict = dict;
    NSString *name = [dict valueForKey:@"name"];
    NSString *phone = [dict valueForKey:@"phone"];
    
    self.nameAndphoneLabel.text = [NSString stringWithFormat:@"%@ %@",name,phone];
    self.addressLabel.text = [dict valueForKey:@"full_address"];
}

- (void)editButtonClickAction {
    if (self.editBtnClickCallBack) {
        self.editBtnClickCallBack(self.dict);
    }
}

- (void)setCanselect:(BOOL)canselect {
    _canselect = canselect;
    if (self.canselect) {
        self.checkImv.hidden = NO;
        self.leftc.constant = 40.0f;
    } else {
        self.checkImv.hidden = YES;
        self.leftc.constant = 12.0f;
    }
}




@end
